//
//  WAdvertScrollView.m
//  Go!
//
//  Created by 凌風 on 16/7/11.
//  Copyright © 2016年 凌风. All rights reserved.
//

#import "WAdvertScrollView.h"

@implementation WAdvertScrollView

- (instancetype)initWithFrame:(CGRect)frame ImageArray:(NSArray *)imgArr
{
    self = [super initWithFrame:frame];
    if (self) {
        _imageArray = imgArr;
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    
    if (self.imageArray && self.imageArray.count) {
        
        [self.imageArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            UIImage *image;
            
            if ([obj isKindOfClass:[NSString class]]) {
                image = [UIImage imageNamed:obj];
            } else if ([obj isKindOfClass:[UIImage class]]) {
                image = obj;
            }
            
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(idx * self.frame.size.width, 0, self.bounds.size.width, self.bounds.size.height)];
            imageView.image = image;
            
//            NSLog(@"%@", NSStringFromCGRect(imageView.frame));
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            [self addSubview:imageView];
            
        }];
        
        self.pagingEnabled = true;
        
        self.contentSize = CGSizeMake(self.imageArray.count * self.bounds.size.width, self.bounds.size.height);
//        NSLog(@"%@", NSStringFromCGRect(self.frame));
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
